package b.b.g.i;

import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow.OnDismissListener;
import b.i.k.o;
import java.util.WeakHashMap;

/* compiled from: MenuPopupHelper */
public class l {
    public final Context a;
    public final g b;
    public final boolean c;
    public final int d;
    public final int e;
    public View f;
    public int g = 8388611;
    public boolean h;
    public b.b.g.i.m.a i;
    public k j;
    public OnDismissListener k;
    public final OnDismissListener l = new a();

    /* compiled from: MenuPopupHelper */
    public class a implements OnDismissListener {
        public void onDismiss() {
            l.this.c();
        }
    }

    public l(Context context, g gVar, View view, boolean z, int i, int i2) {
        this.a = context;
        this.b = gVar;
        this.f = view;
        this.c = z;
        this.d = i;
        this.e = i2;
    }

    public k a() {
        if (this.j == null) {
            Display defaultDisplay = ((WindowManager) this.a.getSystemService("window")).getDefaultDisplay();
            Point point = new Point();
            defaultDisplay.getRealSize(point);
            if ((Math.min(point.x, point.y) >= this.a.getResources().getDimensionPixelSize(2131165206) ? 1 : null) != null) {
                k dVar = new d(this.a, this.f, this.d, this.e, this.c);
            } else {
                k qVar = new q(this.a, this.b, this.f, this.d, this.e, this.c);
            }
            r0.l(this.b);
            r0.s(this.l);
            r0.o(this.f);
            r0.k(this.i);
            r0.p(this.h);
            r0.q(this.g);
            this.j = r0;
        }
        return this.j;
    }

    public boolean b() {
        k kVar = this.j;
        return kVar != null && kVar.b();
    }

    public void c() {
        this.j = null;
        OnDismissListener onDismissListener = this.k;
        if (onDismissListener != null) {
            onDismissListener.onDismiss();
        }
    }

    public void d(b.b.g.i.m.a aVar) {
        this.i = aVar;
        k kVar = this.j;
        if (kVar != null) {
            kVar.k(aVar);
        }
    }

    public final void e(int i, int i2, boolean z, boolean z2) {
        k a = a();
        a.t(z2);
        if (z) {
            int i3 = this.g;
            View view = this.f;
            WeakHashMap weakHashMap = o.a;
            if ((Gravity.getAbsoluteGravity(i3, view.getLayoutDirection()) & 7) == 5) {
                i -= this.f.getWidth();
            }
            a.r(i);
            a.u(i2);
            i3 = (int) ((this.a.getResources().getDisplayMetrics().density * 48.0f) / 2.0f);
            a.a = new Rect(i - i3, i2 - i3, i + i3, i2 + i3);
        }
        a.d();
    }

    public boolean f() {
        if (b()) {
            return true;
        }
        if (this.f == null) {
            return false;
        }
        e(0, 0, false, false);
        return true;
    }
}
